package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.dao.IReportDao;
import com.ce.pms.report.queryvo.AlreadyBuildAndItemByTimeQueryVO;
import com.ce.pms.report.vo.AlreadyBuildAndItemByTimeReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;


/**
 *
 * 功能描述：财务已收款分栋分项汇总表(时间段）Service
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 黄彦军
 * Created on 2008-11-3
 * Edit author:
 * Edit on:
 * 修改原因:
 */
public class AlreadyBuildAndItemByTimeService implements ICEReportDataSetService {

	private IReportDao reportDao;

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg0) throws CEReportException {
		AlreadyBuildAndItemByTimeQueryVO queryVO = (AlreadyBuildAndItemByTimeQueryVO) arg0;

		return new CEReportDataSet(getData(queryVO),getHeadInfo(queryVO));
	}

	/**
	 * 功能描述: 获取数据 <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<AlreadyBuildAndItemByTimeReportVO> getData(AlreadyBuildAndItemByTimeQueryVO queryVO){
		String precinct = queryVO.getPrecinct();
		String beginDate = DateUtil.convertDateToStr(queryVO.getBeginDate(), "yyyyMMdd");
		String endDate = DateUtil.convertDateToStr(queryVO.getEndDate(), "yyyyMMdd");

		Object [] obj = new Object[]{beginDate,endDate,precinct};

		List<Object[]> temp = reportDao.getDataList("alreadyBuildAndItemByTime", obj);

		List<AlreadyBuildAndItemByTimeReportVO> list =  arrayToVO(temp);
		if (BlankUtil.isBlank(list)){
			list = new ArrayList<AlreadyBuildAndItemByTimeReportVO>();
			AlreadyBuildAndItemByTimeReportVO reportVO = new AlreadyBuildAndItemByTimeReportVO();
			list.add(reportVO);
		}
		return list;
	}

	/**
	 * 功能描述:将已收款分栋分项汇总对象数组 转为 VO数组 <br>
	 *
	 * @param temp
	 * @return Create author:黄彦军 <br>
	 *         Create on:2008-11-7 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	private List<AlreadyBuildAndItemByTimeReportVO> arrayToVO(
			List<Object[]> temp) {
		if (BlankUtil.isBlank(temp)) {
			return null;
		}
		List<AlreadyBuildAndItemByTimeReportVO> list = new ArrayList<AlreadyBuildAndItemByTimeReportVO>();
		for (Object[] obj : temp) {
			AlreadyBuildAndItemByTimeReportVO reportVO = new AlreadyBuildAndItemByTimeReportVO();
			reportVO.setCompanyName((String) obj[0]);		// 物业公司名称
			reportVO.setBuildingName((String) obj[1]);		// 大楼名称
			reportVO.setActualPay((BigDecimal) obj[2]);		// 实收金额
			reportVO.setLatefee((BigDecimal) obj[3]);		// 滞纳金
			reportVO.setOverheadExpenses((BigDecimal) obj[4]);// 管理费
			reportVO.setOnticUpkeep((BigDecimal) obj[5]);	// 本体维修基金
			reportVO.setWaterPay((BigDecimal) obj[6]);		// 水费
			reportVO.setElectricityPay((BigDecimal) obj[7]);// 电费
			reportVO.setSewagePay((BigDecimal) obj[8]);		// 污水处理费
			reportVO.setGarbagePay((BigDecimal) obj[9]);	// 垃圾处理费
			reportVO.setUpkeepPay((BigDecimal) obj[10]);	// 维修费
			reportVO.setAdjustSum((BigDecimal) obj[11]);	// 调整费用合计
			reportVO.setDerateSum((BigDecimal) obj[12]);	// 减免费用合计

			list.add(reportVO);
		}
		return list;
	}

	/**
	 * 功能描述: 设置头信息 <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<String, Object> getHeadInfo(AlreadyBuildAndItemByTimeQueryVO queryVO){
		Map<String, Object> map =new HashMap<String, Object>();
		String beginDate = DateUtil.convertDateToStr(queryVO.getBeginDate(), "yyyy年MM月dd日");
		String endDate = DateUtil.convertDateToStr(queryVO.getEndDate(), "yyyy年MM月dd日");
		map.put("reportHeadStr", "统计时间:"+beginDate+"-"+endDate);
		map.put("printDate", new Date());
		return map;
	}

	public void setReportDao(IReportDao reportDao) {
		this.reportDao = reportDao;
	}


}
